package com.hsd.znsh.converter;

import com.hsd.znsh.entity.SensorGroup;
import com.hsd.znsh.enums.SensorGroupTypeEnum;
import com.hsd.znsh.pojo.output.MonitorVO;
import com.hsd.znsh.pojo.output.SensorGroupVO;
import com.hsd.znsh.repository.UserRepository;
import com.hsd.znsh.utils.BeanUtil;
import com.hsd.znsh.utils.EnumUtil;

import java.util.ArrayList;
import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-25 13:54:52
 */
public class SensorGroupConverter {

    public static SensorGroupVO converterToSensorGroupVO(SensorGroup sensorGroup,
                                                     UserRepository userRepository){
        SensorGroupVO sensorGroupVO=new SensorGroupVO();
        BeanUtil.copyProperties(sensorGroup,sensorGroupVO);
        if(sensorGroup.getCreateUserId()!=null){
            sensorGroupVO.setCreateUsername(userRepository.findOne(sensorGroup.getCreateUserId()).getUsername());
        }
        sensorGroupVO.setSensorGroupTypeName(EnumUtil.getMessageByCode(sensorGroup.getSensorGroupType(), SensorGroupTypeEnum.class));
        return sensorGroupVO;
    }

    public static List<SensorGroupVO> converterToSensorGroupVOList(List<SensorGroup> sensorGroups,
                                                       UserRepository userRepository){
        List<SensorGroupVO> list=new ArrayList<>();
        for(SensorGroup sensorGroup:sensorGroups){
            list.add(converterToSensorGroupVO(sensorGroup,userRepository));
        }
        return list;
    }
}
